package com.iyundao.io.mapper;

import com.iyundao.io.model.SysDept;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SysDeptCustomMapper {

    @Select("select * from sys_dept where sid in (SELECT sid FROM sys_dept " +
            " where sid=(SELECT did from user_dept where uid = #{sid,jdbcType=CHAR}) " +
            " or " +
            " parent_id=(SELECT did from user_dept where uid = #{sid,jdbcType=CHAR}))")
    @Results({
            @Result(column="sid", property="sid", jdbcType= JdbcType.CHAR, id=true),
            @Result(column="real_name", property="realName", jdbcType=JdbcType.VARCHAR),
            @Result(column="show_name", property="showName", jdbcType=JdbcType.VARCHAR),
            @Result(column="flag", property="flag", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_date", property="createDate", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="create_id", property="createId", jdbcType=JdbcType.CHAR),
            @Result(column="orde_by", property="ordeBy", jdbcType=JdbcType.TINYINT)
    })
    List<SysDept> selectByRoleId(String sid);

}
